#include "AnimationView.h"
#include "GUIBase.h"
#include <qgraphicsview.h>


AnimationView::AnimationView(QWidget *parent)
	: QGraphicsScene(parent)
	//: QWidget( parent, 0 ),
	//scene(0, 0, 800, 440),
	//view(&scene,this)
{
	QRectF* sceneRect = new QRectF(0, 0, 870, 510);	//TODO check view's size
	this->setSceneRect(*sceneRect);

	QPixmap bg("Resources/DarkFloor.png");
	QBrush bgBrush(Qt::gray, bg);
	this->setBackgroundBrush(bgBrush);

	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(timerSlot()));
}

void AnimationView::startAnimation()
{
	if(!timer->isActive())
	{
		timer->start(33);
	}
}

void AnimationView::stopAnimation()
{
	timer->stop();
	update(); // One last update for things that change as animation is disabled.
}

void AnimationView::setTimerDelay(int delay)
{
	if(timer->isActive())
	{
		timer->start(delay);
	}
	else
	{
		timer->setInterval(delay);
	}
}

void AnimationView::timerSlot()
{
	//qDebug("TIMER FIRED");
	this->advance();
	this->update();
}
//void AnimationView::addGUIElement( GUIBase element )
//{
//	GUIList.append(element);
//}
